# file:: game_database.rb
# author::  Ralph M. Churchill
# version::
# date::
#
# This source code copyright (C) 2006 by Ralph M. Churchill
# All rights reserved.
#
# Released under the terms of the GNU General Public License
# See LICENSE file for additional information.

require 'database/database'
require 'singleton'

class AccountDatabase < VectorDatabase
    include Singleton
end

class RegionDatabase < VectorDatabase
    include Singleton
end

class RoomDatabase < VectorDatabase
    include Singleton
end

class PortalDatabase < VectorDatabase
    include Singleton
end

class CharacterDatabase < TemplateInstanceDatabase
    include Singleton
end

class ItemDatabase < TemplateInstanceDatabase
    include Singleton
end

# Acts like a Vector-/Map-Database
class CommandDatabase
    include Singleton, Enumerable
    attr_accessor :commands

    def each
        self.commands.each{|c| yield c}
    end
    def add(command)
        self.commands |= [command]
        command
    end
    alias_method :orig_commands,:commands
    def commands
        self.commands=[] if self.orig_commands.nil?
        self.orig_commands
    end
    def give_commands_to_player(player)
        self.commands.each do |command_name|
            klass = Object.const_get(command_name)
            if klass and not (klass.const_defined?('RANK') and
                             klass::RANK > player.rank) then
                player.add_command(klass.new(player))
            end
        end
    end
end
